<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        a {
            color: brown;
            text-decoration: none;
        }
        table {
            table-layout: fixed;
            width: 60%;
            border-collapse: collapse;
            border: 3px solid purple;
            margin: 100px auto;
        }

        thead th:nth-child(1) {
            width: 30%;
        }

        thead th:nth-child(2) {
            width: 20%;
        }

        thead th:nth-child(3) {
            width: 15%;
        }

        thead th:nth-child(4) {
            width: 35%;
        }

        th,
        td {
            padding: 20px;
            text-align: center;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            
        </tbody>
    </table>
</body>
<script>
    // 1.准备数据
    var data = [
        {
        name: '唐僧',
        subject: 'JavaScript',
        score: 59
    },
    {
        name: '孙悟空',
        subject: 'JavaScript',
        score: 99
    },
    {
        name: '猪八戒',
        subject: 'JavaScript',
        score: 100
    },
    {
        name: '沙僧',
        subject: 'JavaScript',
        score: 80
    }]

    var tbody = document.querySelector('tbody')

    for (var i = 0;data.length > i;i++) {
        // 创建行
        var tr = document.createElement('tr')
        tbody.appendChild(tr)
        //导入各行内容到单元格
        for (var k in data[i]) {
            var td = document.createElement('td')
            td.innerHTML = data[i][k]
            tr.appendChild(td)
        }
        var td = document.createElement('td')
        td.innerHTML = '<a href="javascript:;"">删除</a>'
        tr.appendChild(td)
    }
    //创建删除按钮
    var del = document.querySelectorAll('a')
        for (var j = 0;j<del.length;j++) {
            del[j].onclick = function(){
                tbody.removeChild(this.parentNode.parentNode)
            }
        }
</script>

</html>